package cn.tedu.start.controller.stock;


import cn.tedu.commons.response.JsonResult;
import cn.tedu.pojo.dto.order.OrderTebleDTO;
import cn.tedu.pojo.stock.dto.StockDTO;
import cn.tedu.service.stock.IStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "5,库存模块")
@RestController
@RequestMapping("/admin/stock")
public class StockController {
    @Autowired(required = false)
    private IStockService stockService;

    //管理员进行库存的修改
    @ApiOperation("管理员进行库存的修改")
    @GetMapping("/update")
    public JsonResult updateStock(StockDTO stockDTO){
        stockService.updateStock(stockDTO);
        return JsonResult.ok("库存修改完成");
    }

    //通过订单来进行库存的减少
    @ApiOperation("通过订单进行库存的减少")
    @PostMapping("order/reduce")
    public JsonResult updateStockByOrder(@RequestBody OrderTebleDTO orderTebleDTO){
        stockService.updateStockByOrder(orderTebleDTO);
        return JsonResult.ok("订单减少库存完成");
    }

}
